package test_junit_merchant.ManageMerchant;

import org.openqa.selenium.By;
import util.BaseDriver;

/**
 * Created by Eric on 2018/1/31.
 * 商户-仓库新建
 */
public class Warehouse extends BaseDriver{
    private static Warehouse ns = new Warehouse();
    public static Warehouse getInstance(){
        return ns;
    }

    private Warehouse() {
    }

    /***
     * 执行操作
     * @param storageName 仓库名
     * @param responseNum 负责人手机号码
     * @return
     */
    public void add(String storageName, String responseNum) throws InterruptedException {
        try {
            System.out.println("进入仓库新增测试");

            driver.switchTo().frame(driver.findElement(By.xpath("//div[@id='page-wrapper']/div[2]/iframe[2]")));

            // 新增仓库 按钮
            driver.findElement(By.xpath("//button[@onclick='add1()']")).click();
            System.out.println("点击新增按钮");
            Thread.sleep(1000);

            driver.switchTo().frame(0);

            // 仓库名称
            driver.findElement(By.name("name")).sendKeys(storageName);
            System.out.println("输入仓库名称：" + storageName);

            // 仓库类型
            driver.findElement(By.xpath("//select[@name='type']/option[2]")).click();

            // 负责人手机号码
            driver.findElement(By.name("phone")).sendKeys(responseNum);
            System.out.println("输入负责人手机号码：" + responseNum);

            driver.switchTo().parentFrame();

            // 确定 按钮
            driver.findElement(By.linkText("确定")).click();
            Thread.sleep(1000);

            // 确认 新增窗体消失

            int size = driver.findElements(By.name("name")).size();
            if (size == 0) {
                System.err.println("人员新增成功");
            } else {
                System.out.println("人员新增成功");
            }
        } catch (Error error) {
            System.err.println("人员新增失败");
            error.printStackTrace();
            // shot here
        }
    }
}
